#include <stdio.h>

int main(void)
{
    int ret = 0;
    int ch = 0;

    FILE *fp = tmpfile();
    if(fp == NULL)
    {
        perror("fopen temp file fail");
        return -1;
    }

    ret = fputs("hello mingri\nhello world\n", fp);
    if(ret == EOF)
    {
        if(feof(fp))
        {
            printf("end of file\n");
        }
        else if(ferror(fp))
        {
            printf("fputs file errr!!!\n");
            return -1;
        }
    }

    rewind(fp);
    ch = fgetc(fp);
    while(1)
    {
        if(ch == EOF)
        {
            if(feof(fp))
            {
                printf("end of file\n");
                break;
            }
            else if(ferror(fp))
            {
                printf("fputs file errr!!!\n");
                break;
            }
            printf("%c", ch);
        }
        printf("%c", ch);
        ch = fgetc(fp);
    }
}